<template>
    <div class="app-container">
        <a-card>
            <BasicTable ref="tableRef" :params="params" :columns="columns" :query="query" :selectbox="false">
                <template #form>
                    <a-form-item label="告警代码" name="code">
                        <a-input v-model:value="params.code" placeholder="请输入告警代码" />
                    </a-form-item>
                    <a-form-item label="告警名称" name="name">
                        <a-input v-model:value="params.name" placeholder="请输入告警名称" />
                    </a-form-item>
                </template>
                <template #button>
                    <a-button type="primary" @click="open(drawerRef)">
                        <template #icon>
                            <PlusOutlined />
                        </template>
                        新增
                    </a-button>
                </template>
                <template #table="{ body }">
                    <template v-if="body.column.key === 'action'">
                        <a-button type="link" @click="open(drawerRef, body.record)">
                            <template #icon>
                                <EditOutlined />
                            </template>
                            编辑
                        </a-button>
                        <a-popconfirm title="确定要删除吗?" @confirm="del(deleteById, body.record.id, tableRef)">
                            <a-button type="link">
                                <template #icon>
                                    <DeleteOutlined />
                                </template>
                                删除
                            </a-button>
                        </a-popconfirm>
                    </template>
                </template>
            </BasicTable>
        </a-card>
        <Drawer ref="drawerRef" @close="refresh(tableRef)" />
    </div>
</template>
<script setup name="AlarmErrorModule">
import { reactive, ref } from 'vue'
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
import { query, deleteById } from '/@/api/Inverter/AlarmError/index.js'
import { useBasicTable } from '@iframe/tools/mixins/BasicTableMixins'
import { BasicTable } from '@iframe/tools/components'
import Drawer from './Drawer.vue'

const { refresh, del, open } = useBasicTable()
const tableRef = ref()
const drawerRef = ref()
const params = reactive({
    code: null,
    name: null
})
const columns = [
    {
        title: '告警代码',
        dataIndex: 'code',
        key: 'code',
        width: 150
    },
    {
        title: '告警英文名',
        dataIndex: 'nameEs',
        key: 'nameEs',
        width: 250
    },
    {
        title: '告警名称',
        dataIndex: 'name',
        key: 'name',
        width: 250
    },
    {
        title: '解决方案',
        dataIndex: 'solution',
        key: 'solution'
    },
    {
        title: '操作',
        key: 'action',
        align: 'center',
        width: 200
    }
]
</script>
